<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑用户</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<form class="layui-form" style="width: 80%;">
    <input type="hidden" name="adminId" th:value="${admin.adminId}">
        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-block">
                <input type="text" id="nickname" class="layui-input"
                       lay-verify="required" name="nickname" th:value="${admin.nickname}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block">

                <input th:each="role:${roles}" type="radio" name="roleId" th:value="${role.roleId}" th:title="${role.roleName}" th:checked="${role.roleId == admin.roleId}" >
                <!--<input type="radio" name="sex" value="1" title="男" th:checked="${user.sex == '1'}" >
                <input type="radio" name="sex" value="0" title="女" th:checked="${user.sex == '0'}">
                <input type="radio" name="sex" value="2" title="保密" th:checked="${user.sex == '2'}">-->
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="updAdmin" lay-submit="" lay-filter="updAdmin">立即保存</button>
            </div>
        </div>
</form>



<script th:src="@{/src/layui.js}"></script>
<script>
    layui.use(['form','laydate','layer','jquery'],function () {
        var form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer,
            $ = layui.jquery;
        laydate.render({
            elem:'#birthday',
            max:'new Date()',
            trigger:'click'
        })
        //修改
        form.on('submit(updAdmin)',function (data) {
            $.ajax({
                url:'/admin/updAdmin',
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('修改成功',{icon:1},function () {
                            parent.layer.closeAll("iframe");
                            parent.location.reload();
                        });
                    }else{
                        layer.msg(res.message,{icon:5});
                    }
                }
            })
            return false; //表单不提交，通过ajax的方式异步提交数据。
        })


    })
</script>
</body>
</html>